package com.my.ext.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.my.ext.entity.Group;
import com.my.ext.service.IGroupService;
import com.my.ext.utils.ResultObject;

@RestController
@RequestMapping(value= {"/group","/api/group"}, method = {RequestMethod.GET, RequestMethod.POST})
public class GroupController {

	@Autowired
	IGroupService service;
	
	@RequestMapping("/queryAll")
	public ResultObject queryAll(int page, int size) {
		PageInfo<Group> info = service.queryAllGroup(page, size);
		ResultObject obj = new ResultObject();
		obj.setData(info);
		obj.setStatus(1);
		return obj;
	}
	
	@RequestMapping("/addGroup")
	public ResultObject addGroup(Group group) {
		int i = service.addGroup(group);
		ResultObject obj = new ResultObject();
		obj.setStatus(1);
		obj.setData(1);
		return obj;
	}
	
	@RequestMapping("/queryByOrgId")
	public ResultObject queryGroupsByOrgid(int org) {
		PageInfo<Group> data = service.queryGroupsByOrgid(org);
		ResultObject obj = new ResultObject();
		obj.setStatus(1);
		obj.setData(data.getList());
		return obj;
	}
	
}
